package com.thientan.model

import com.thientan.model.enums.LoaiNhanVien

/**
 * Domain class used to represent entity from table NHAN_VIEN
 * @author DINH HONG CHAU
 *
 */
class NhanVien implements Serializable {
	static constraints = {
		doiTruong(nullable: true)
		password(nullable : true)
		maNv(maxSize: 15, validator : { val, object -> 
            return (object.id == null && NhanVien.countByMaNv(val) == 0)||
            (object.id != null && NhanVien.countByMaNvAndIdNotEqual(val, object.id) == 0)
        })
		hoTen(maxSize: 50)
	}

	static mapping = {
		table 'NHAN_VIEN'
		id generator : 'increment'
		sort maNv : "asc"
		columns {
			id column : 'NHAN_VIEN_ID'
			kichHoat column: 'KICH_HOAT', class: Boolean
			doiTruong column: 'DOI_TRUONG_ID'
		}
	}

	String maNv
	String hoTen
	String password
	NhanVien doiTruong
	LoaiNhanVien loaiNhanVien
	boolean kichHoat = true

	Set<HopDong> hopDongs = []
	static hasMany = [hopDongs : HopDong]
	static mappedBy = [hopDongs : 'nvThuNgan']
}
